package com.sojoys.artifact.pool;

import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

/**
 * @author : DengYing
 * @CreateDate : 2017年12月20日 下午3:25:37
 * @Description ：Please describe this document
 */
public class StringBuilderPool {
	
	private StringBuilderPool() {
	}

	private static StringBuilderPool ME = new StringBuilderPool();

	public static StringBuilderPool me() {
		return ME;
	}
	
	private GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
	
	{
		poolConfig.setMinIdle(16);
		poolConfig.setMaxIdle(64);
	}
	private GenericObjectPool<StringBuilder> pool = new GenericObjectPool<>(new StringBuilderFactory(), poolConfig);
	
	public StringBuilder borrowObject(){
		try {
			return pool.borrowObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public void returnObject(StringBuilder sb){
		pool.returnObject(sb);
	}
	
	
	
}
